import java.util.LinkedList;

public class LeetCode3_MaxSubString {
    public int lengthOfLongestSubstring(String s) {
        int len = 0;
        LinkedList<Character> list = new LinkedList<>();
        int left = 0;
        int right = 0;
        while (right < s.length()) {
            list.add(s.charAt(right++));
            len = Math.max(len, list.size());
            if (right >= s.length()) {
                break;
            }
            while (list.contains(s.charAt(right))) {
                list.remove(0);
                left++;
            }
        }

        return len;
    }
}
